package com.example.crm.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.crm.entity.TeamMember;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 团队成员Mapper接口
 */
@Mapper
public interface TeamMemberMapper extends BaseMapper<TeamMember> {
    
    /**
     * 根据用户ID查询所属团队ID列表
     * @param userId 用户ID
     * @return 团队ID列表
     */
    @Select("SELECT team_id FROM crm_team_member WHERE user_id = #{userId} AND is_deleted = 0")
    List<Long> selectTeamIdsByUserId(@Param("userId") Long userId);
    
    /**
     * 根据团队ID查询成员列表
     * @param teamId 团队ID
     * @return 成员列表
     */
    @Select("SELECT m.*, u.username, u.real_name, u.email, u.phone FROM crm_team_member m " +
            "LEFT JOIN sys_user u ON m.user_id = u.id " +
            "WHERE m.team_id = #{teamId} AND m.is_deleted = 0")
    List<TeamMember> selectMembersByTeamId(@Param("teamId") Long teamId);
} 